package com.example.xm;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

import com.example.xm.adapter.viewpager.VPAdapter;
import com.example.xm.utiles.SpUtils;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

public class PagerActivity extends AppCompatActivity {

    @BindView(R.id.pager)
    ViewPager pager;
    Button jinru;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pager);
        ButterKnife.bind(this);
        initView();
        initListener();
    }

    private void initView() {
        //判断是否是第一次应用
        int isfirst = SpUtils.getInstance().getInt("comein");
        if (isfirst == 0) {
            View vp1 = LayoutInflater.from(this).inflate(R.layout.vp1, null);
            View vp2 = LayoutInflater.from(this).inflate(R.layout.vp2, null);
            View vp3 = LayoutInflater.from(this).inflate(R.layout.vp3, null);
            View vp4 = LayoutInflater.from(this).inflate(R.layout.vp4, null);
            jinru = vp4.findViewById(R.id.btn_jinru);
            ArrayList<View> views = new ArrayList<>();
            views.add(vp1);
            views.add(vp2);
            views.add(vp3);
            views.add(vp4);
            VPAdapter vpAdapter = new VPAdapter(views);
            pager.setAdapter(vpAdapter);
            jinru.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(PagerActivity.this, MainActivity.class);
                    startActivity(intent);
                    finish();
                    SpUtils.getInstance().setValue("comein", 1);
                }
            });
        } else {
            Intent intent = new Intent(PagerActivity.this, MainActivity.class);
            startActivity(intent);
            finish();
        }
    }

    private void initListener() {

    }
}